#ifndef __TwApplication_H__
#define __TwApplication_H__

#include "TwCamera.h"
#include "TwSceneManager.h"
#include "TwScreenTwement.h"

class TwApplication
{
public:
	TwApplication();
	virtual ~TwApplication();

	virtual bool initialize(HWND wnd);
	virtual void terminate();

	virtual void process();
	virtual void beginFrame();
	
	virtual void beginUpdate();
	virtual void update();
	virtual void endUpdate();

	virtual void beginRender();
	virtual void render();
	virtual void endRender();

	virtual void renderScene();
	virtual void renderScreenItems();

	virtual void displayFrame();
	virtual void endFrame();

	virtual void setPause(bool pause);
	virtual bool getPause() const;
	virtual TimeValue getCurrentTime(bool ignorePaused = false) const;

	virtual TwCamera* getCamera();
	virtual TwSceneManager* getScene();
	
	virtual DWORD getFillMode() const;
	virtual void setFillMode(DWORD fm);

	virtual void addScreenTwement(TwScreenTwement* element);

	virtual HWND getReferenceWindow() const;

protected:
	virtual bool createDevice();
	virtual bool createCamera();
	virtual bool createScene();

	virtual bool _measureTime();

	virtual bool _setScreenSpaceCamera();
	virtual void _useScreenSpaceCamera();
	virtual void _renderScreenTwements();

protected:
	TwCamera*			m_mCamera;
	TwSceneManager*		m_mScene;

	bool				m_mZDefaultEnable;
	DWORD				m_mFillMode;

	TimeValue			m_mLastTime;
	TimeValue			m_mCurrentTime;
	TimeValue			m_mFrameTime;
	TimeValue			m_mAccumTime;
	
	bool				m_mPause;
	TimeValue			m_mAccumTimeWithPause;

	// Frame rate limitation
	TimeValue			m_mMinFramePeriod;
	TimeValue			m_mLastFrame;

	TwCamera*			m_mOrthoCamera;
	TwScreenTwementList	m_mScreenTwements;

	HWND				m_mReferenceWindow;
};

#endif //__TwApplication_H__